import './new_link.html';




Template.new_link.onRendered(function () {
	
});


Template.new_link.helpers({
	
});


Template.new_link.events({
	'submit .new-link-add'(event) {
	    event.preventDefault();

	    const target = event.target;
	    const name = target.getElementsByTagName("input")[0];
		const url = target.getElementsByTagName("input")[1];
		const area = target.getElementsByTagName("input")[2];
		const cate = target.getElementsByTagName("input")[3];
		const weight = target.getElementsByTagName("input")[4];

	    Meteor.call('links.insert', name.value, url.value, area.value, cate.value, weight.value, (error) => {
	      if (error) {
	        alert(error.error);
	      } else {
	        name.value = '';
			weight.value = '';
			url.value = '';
			area.value = '';
			cate.value = '';

	        $('#new-modal').modal('hide');
					FlashMessages.sendSuccess("链接创建成功");
	      }
	    });

	  },
});